class Factory {
    private String lastKind;

    public Fruit createFruit(String kind) {
        this.lastKind = kind;
        if (kind.equals("A")) return new Apple();
        if (kind.equals("B")) return new Banana();
        return null;
    }

    public Memento saveToMemento() {
        return new Memento(lastKind);
    }

    public Fruit restoreFromMemento(Memento m) {
        return createFruit(m.getKind());
    }
}